﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cms.Entity.LeaveWord;
using Frame.Lib.Utilities;
using Frame.Lib.Web;
using Cms.BLL.LeaveWord;

namespace Cms.Admin.LeaveWord
{
    public partial class List : PageList
    {
        private LeaveWordBO _leaveWord;
        private LeaveWordBO LeaveWord
        {
            get
            {
                if (_leaveWord == null)
                {
                    _leaveWord = new LeaveWordBO();
                }
                return _leaveWord;
            }
        }

        private PagerSortSetting _setting;

        protected void Page_Load(object sender, EventArgs e)
        {
            _setting = this.Footer1.InitPager(new BindViewHandler(BindView));            

            if (!IsPostBack)
            {
                BindView();
            }
            base.InitSelectID(hidSelectIDs);

            AddAttr();

        }

        private void AddAttr()
        {
            JSUtil.DelConfirm(btnDelete, "留言");       
            JSUtil.ClickBtn(lnkDelete, btnDelete);

        }

        private void BindView()
        {
            this.InitLV(lv, lvHeader);

            lv.DataKeyNames = new string[] { "ID" };
            IEnumerable<LeaveWordInfo> list = this.LeaveWord.GetList().OrderByDescending(t => t.InputTime);

            _setting.RecordCount = list.Count();
            lblStatistic.Text = "[共" + _setting.RecordCount + "条留言]";

            lv.DataSource = list.Skip(_setting.SkipCount).Take(_setting.PageSize);
            lv.DataBind();
        }

        protected string GetContent(object content)
        {
            return  Server.HtmlEncode(content.ToString());
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (strSelectIDs == "")
            {
                return;
            }
            List<int> lstSelectIDs = StrUtil.SplitToInt(strSelectIDs);

            //要删除相关的图片和附件
            LeaveWord.Delete(lstSelectIDs);
            BindView();
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            BindView();
        }
    }
}
